package com.schoolcloud.share.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.share.entity.SetSections;
import com.schoolcloud.share.query.SetSectionQuery;
import com.schoolcloud.share.service.SetSectionsService;
import com.schoolcloud.share.mapper.SetSectionsMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
* @author hongmizfb
* @description 针对表【set_sections(合集章节结构)】的数据库操作Service实现
* @createDate 2025-05-16 18:35:15
*/
@Service
public class SetSectionsServiceImpl extends ServiceImpl<SetSectionsMapper, SetSections>
    implements SetSectionsService{

    @Override
    public Page<SetSections> getSetSectionsPage(SetSectionQuery query) {
        String setId = query.getSetId();
        String title = query.getTitle();
        return lambdaQuery().eq(StrUtil.isNotBlank(setId), SetSections::getSetId, setId)
                .like(StrUtil.isNotBlank(title), SetSections::getTitle, title)
                .page(query.toMpPage());
    }

    @Override
    public void createSetSection(SetSections setSections) {
        setSections.setCreatedTime(LocalDateTime.now());
        save(setSections);
    }

    @Override
    public SetSections getBySectionId(Integer sectionId) {
        return lambdaQuery().eq(SetSections::getSectionId, sectionId).one();
    }

    @Override
    public List<SetSections> getListBySetId(Integer setId) {
        return lambdaQuery().eq(SetSections::getSetId, setId).list();
    }
}




